﻿// JavaScript Document
window.onload=function(){
	var eChange = $('.Entrance_Change') ;
	var regBox = $('#Reg_Box') ;
	var loginBox = $('#Login_Box') ;
	var submitButton = $('.Entrance_Button') ;  //提交按钮
	var regInput = $('#Reg_Box .Entrance_Input') ;  //注册输入框
	var loginInput = $('#Login_Box .Entrance_Input') ;  //登录输入框
	var regInfoBox = $('#Reg_Box .Input_Info') ;  //注册输入提示
	var loginInfoBox = $('#Login_Box .Input_Info') ;  //登录输入提示
	eChange[1].onclick = function(){
		regBox.stop(true).animate({marginLeft:'30px',opacity:'0'},'fast');
		regBox.fadeOut(0,show);
		function show(){loginBox.fadeIn();regBox.css({'margin-Left':'0px','opacity':'1'});}
			
	}
	eChange[0].onclick = function(){
		loginBox.stop(true).animate({marginLeft:'30px',opacity:'0'},'fast');
		loginBox.fadeOut(0,show);
		function show (){regBox.fadeIn();loginBox.css({'margin-Left':'0px','opacity':'1'});}
	}
	submitButton[1].onclick = function(){
		function checkEmail(obj){
			var re = new RegExp(/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/)
			return re.test(obj.value);
		}
		function checkPassword(obj){
			var re = new RegExp(/^[\w]{6,16}$/)
			return re.test(obj.value);
		}
		function checkAge(obj){
			var re = new RegExp(/^[0-9]{2}$/)
			return re.test(obj.value);
		}
		var flag = true ;  //标识检验表单
		//验证邮箱
		if(regInput[0].value=="")
		{
			regInfoBox[0].innerHTML="请填写邮箱！";
			flag = false;
		}
		else if(!checkEmail(regInput[0]))
		{
			regInfoBox[0].innerHTML="邮箱格式错误！";
			flag = false;
		}
		else
		{
			regInfoBox[0].innerHTML="格式正确！";
		}
		//验证密码
		if(regInput[1].value=="")
		{
			regInfoBox[1].innerHTML="请填写密码！";
			flag = false;
		}
		else if(regInput[1].value.length<6)
		{
			regInfoBox[1].innerHTML="密码长度过短！";
			flag = false;
		}
		else if(regInput[1].value.length>16)
		{
			regInfoBox[1].innerHTML="密码长度过长！";
			flag = false;
		}
		else if(!checkPassword(regInput[1]))
		{
			regInfoBox[1].innerHTML="密码格式错误！";
			flag = false;
		}
		else
		{
			regInfoBox[1].innerHTML="格式正确！";
		}
		//验证二次密码
		if(regInput[2].value=="")
		{
			regInfoBox[2].innerHTML="请再次输入密码！";
			flag = false;
		}
		else if(regInput[2].value!=regInput[1].value)
		{
			regInfoBox[2].innerHTML="两次输入密码不一致！";
			flag = false;
		}
		else if(!checkPassword(regInput[2]))
		{
			regInfoBox[2].innerHTML="密码格式错误！";
			flag = false;
		}
		else
		{
			regInfoBox[2].innerHTML="格式正确！";
		}
		//验证年龄
		if(!checkAge(regInput[4]))
		{
			regInfoBox[4].innerHTML="年龄格式错误！";
			flag = false;
		}
		else
		{
			regInfoBox[4].innerHTML="格式正确！";
		}
	}
}